package login;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/success")
public class successLogin extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html;charset=UTF-8");
        resp.getWriter().println("登录成功");
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        resp.getWriter().println("您的用户名是："+username+",密码是"+password);
        Cookie cookie = new Cookie("msg","成功");
        resp.addCookie(cookie);
        //把设置刷新响应头放在获取输出流后，刷新无法实现
        //resp.getOutputStream().println("abc");
        resp.setHeader("refresh","4;http://www.baidu.com");
        //resp.getWriter().println("4秒后到主页。。。。");
    }
}
